package com.jt.controller;

import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.vo.EasyUITable;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jt.service.ItemService;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;
import java.util.Date;

@RestController
@RequestMapping("/item/")
public class ItemController {

	@Autowired
	private ItemService itemService;

	// 分页查找
	@RequestMapping("query")
	public EasyUITable findItemByPage(Integer page, Integer rows) {
		return itemService.findItemByOage(page, rows);
	}

	// 入库操作
	@RequestMapping("/save")
	public SysResult saveItem(Item item, ItemDesc itemDesc) {
		itemService.saveItem(item, itemDesc);
			return SysResult.success();

	}

	// 更新操作
	@RequestMapping("/update")
	public SysResult updateItem(Item item, ItemDesc itemDesc) {
		itemService.updateItem(item,itemDesc);
		return SysResult.success();
	}

	// 删除
	@RequestMapping("/delete")
	public SysResult deleteItemById(Long[] ids) {
		itemService.deleteItemById(ids);
		return SysResult.success();
	}

	// 上架下架操作
	@RequestMapping("updateStatus/{status}")
	public SysResult updateStatus(@PathVariable Integer status, Long[] ids) {
		itemService.updateStatus(status, ids);
		return SysResult.success();
	}

	// 根据商品Id,查询商品的详情信息.
	@RequestMapping("/query/item/desc/{itemId}")
	public SysResult findItemDescById(@PathVariable Long itemId) {
		ItemDesc itemDesc = itemService.findItemDescById(itemId);
		return SysResult.success(itemDesc);
	}
}
